package io.unicorn.modules.water.controller;

import com.alibaba.fastjson.JSONObject;
import io.unicorn.common.utils.ExcelUtils;
import io.unicorn.common.utils.PageUtils;
import io.unicorn.common.utils.R;
import io.unicorn.modules.water.service.AllReportService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("water/allreport")
public class AllReportController {
    @Autowired
    AllReportService allReportService;

    @RequestMapping("/reportarea")
    @RequiresPermissions("water:allreport:reportarea")
    public List<Map<String,Object>> queryReportArea(@RequestParam Map<String, Object> params){
        List<Map<String,Object>> page = allReportService.queryReportArea(params);
        return page;
    }

    @RequestMapping("/export")
    @RequiresPermissions("water:allreport:reportarea")
    public void export(@RequestParam Map<String, Object> params,
                       HttpServletRequest request,
                       HttpServletResponse repsonse){
        JSONObject jsonObject = JSONObject.parseObject((String)params.get("params"));
        List<?> listEntity = allReportService.exportReportArea(jsonObject);

        ExcelUtils.exportXlsx(
                repsonse,
                "export",
                "io.unicorn.modules.water.entity.allReportEntity",
                listEntity);
    }
}
